package edu.sctu.xiangkun.day201506.day20150605.TextThree;

import java.util.StringTokenizer;

/**
 * Created by lenovo on 2015/6/5.
 */
public class TokenizerDemo {

    private String string;
    public TokenizerDemo(String string){
        this.string = string;
    }

    public void useOne() {

        StringTokenizer stringTokenizer = new StringTokenizer(string);
        int number = stringTokenizer.countTokens();
        System.out.println("stringTokenizer.countTokens() = " + number);

        while (stringTokenizer.hasMoreElements()) {
            System.out.println(" stringTokenizer.nextElement() = " + stringTokenizer.nextElement());
        }
    }

    public void useTwo(){
        StringTokenizer stringTokenizer1 = new StringTokenizer(string);
        int number1 = stringTokenizer1.countTokens();
        System.out.println("stringTokenizer1.countTokens() = " + number1);

        while (stringTokenizer1.hasMoreTokens()) {
            System.out.println("stringTokenizer1.nextToken() = " + stringTokenizer1.nextToken());
        }
    }

    public static void main(String[] args) {
        TokenizerDemo tokenizerDemo = new TokenizerDemo("this is my first program");
        tokenizerDemo.useOne();
        tokenizerDemo.useTwo();
    }
}
